home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / PROGEDIT / 0748.ZIP / SHIFT < prev    next >
Text File  |  1986-12-29  |  1KB  |  40 lines

  1. /* This macro shifts a marked block of text left or right. You can do */
  2. /* the same thing my marking the area to indent, using the 'indent' */
  3. /* block command, and using the arrow keys. */
  4.  
  5. shift()
  6. {
  7.   int line1, line2;
  8.   int n, j;
  9.  
  10.   /* Prompt the user for the indent width, and check for a bad number. */
  11.   n = atoi(get_tty_str("How many spaces (default 2) ?"));
  12.   if (n == 0)  n = 2;
  13.  
  14.   line1 = marked_line();    /* get the marked range */
  15.   line2 = currlinenum();
  16.   goline(line1);            /* set the cursor to the start of the area */
  17.   gobol();
  18.  
  19.   while (currlinenum() <= line2)
  20.   {
  21.     if (n >= 0)         /* shift rightwards - insert n spaces */
  22.     {
  23.       gobol();
  24.       insert(repstr(" ", n));
  25.     }
  26.     else                /* a negative amount means to shift leftwards */
  27.     {
  28.       j = -n;
  29.       while (j > 0)     /* delete 'n' characters */
  30.       {
  31.         delchar();
  32.         j = j - 1;
  33.       }
  34.     }
  35.     down();             /* move down to the next line */
  36.   }
  37.  
  38.   clear_mark();         /* remove any existing marks */
  39. }
  40.